package com.lz.football.module.activity.makestar
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	import com.lz.football.module.activity.IMakeStar;
	
	import common.BaseView.BaseView;
	import common.BaseView.GoodItem;
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;

	/**
	 * 七日造星活动 
	 * @author Administrator
	 * 
	 */	
	public class MakeStarView extends BaseView implements IMakeStar
	{
		/**
		 *领取的状态ID 
		 */
		private var _selectId:int;
		private var _list:Vector.<GoodItem>;
		/**
		 *第一个领取按钮 
		 */		
		public static var firstBtn :SimpleButton;
		/**
		 *关闭按钮 
		 */		
		public static var closeBtn :SimpleButton;
		
		public function MakeStarView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.makestar");
			if(symbolSkin == null)return;
			this.addChild(symbolSkin);
			
			_windowBg = symbolSkin.makestarBg;
			isDrag = true;
			isCloseBtn = true;
			
			_viewHeight = symbolSkin.height;
			_viewWidth  =symbolSkin.width;
			moveClose(_viewWidth - 35,28);
			onResizeHandler();
			addEvtListener();
			setItem();
			//@lake 2013-11-15
			firstBtn = symbolSkin.btn_1;
			closeBtn =_closeBtn;
		}
		
		
		/**
		 *设置物品 
		 * 
		 */
		private function setItem():void
		{
			_list = new Vector.<GoodItem>();
			var goods:GoodsVo;
			var item:GoodItem
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.OTHER,26);
			item= getItem(goods);
			item.x = 41;
			item.y = 335;
			
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.PLAYERCARD,917);
			item= getItem(goods);
			item.x = 139;
			item.y = 335;
			
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.FOOTWEAR,4);
			item= getItem(goods);
			item.x = 239;
			item.y = 335;
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.OTHER,1);
			item= getItem(goods);
			item.x = 339;
			item.y = 335;
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.OTHER,2);
			item= getItem(goods);
			item.x = 439;
			item.y = 335;
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.MATERIAL,18);
			item= getItem(goods);
			item.x = 539;
			item.y = 335;
			
			goods= AppData.getInstance().goodsManager.getGoodsByTypeAndId(GoodsType.OTHER,17);
			item= getItem(goods);
			item.x = 639;
			item.y = 335;
			
		}
		private function getItem(goods:GoodsVo):GoodItem
		{
			var item:GoodItem = new GoodItem();
			
			item.initUI();
			item.data = goods;
			this.addChild(item);
			_list.push(item);
			return item;
		}
		
		override public function addEvtListener():void
		{
			symbolSkin.btn_1.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_2.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_3.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_4.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_5.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_6.addEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_7.addEventListener(MouseEvent.CLICK,onClickHandler);
			
		}
		private function onClickHandler(event:MouseEvent):void
		{
//			removeEvtListener();
			switch(event.target)
			{
				case symbolSkin.btn_1:
					_selectId = 1;
					symbolSkin.btn_1.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:1},true));
					break;
				case symbolSkin.btn_2:
					_selectId = 2;
					symbolSkin.btn_2.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:2}));
					break;
				case symbolSkin.btn_3:
					_selectId = 3;
					symbolSkin.btn_3.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:3}));
					break;
				case symbolSkin.btn_4:
					_selectId = 4;
					symbolSkin.btn_4.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:4}));
					break;
				case symbolSkin.btn_5:
					_selectId = 5;
					symbolSkin.btn_5.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:5}));
					break;
				case symbolSkin.btn_6:
					_selectId = 6;
					symbolSkin.btn_6.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:6}));
					break;
				case symbolSkin.btn_7:
					_selectId = 7;
					symbolSkin.btn_7.removeEventListener(MouseEvent.CLICK,onClickHandler);
					this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_MAKESTAR_AWARD,{id:7}));
					break;
			}
			
		}
		override public function removeEvtListener():void
		{
			symbolSkin.btn_1.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_2.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_3.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_4.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_5.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_6.removeEventListener(MouseEvent.CLICK,onClickHandler);
			symbolSkin.btn_7.removeEventListener(MouseEvent.CLICK,onClickHandler);
			super.removeEvtListener();
		}
		/**
		 *关闭按钮 
		 * @param event
		 * 
		 */		
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE,null,true));
		}
		override public function destroyView():void
		{
			removeEvtListener();
			while(_list.length)
			{
				_list.pop().destroyView();
			}
			_list = null;
			super.destroyView();
			closeBtn = null;
			firstBtn = null;
		}
		/**
		 *活跃度信息 
		 * @param $obj
		 * 
		 */
		public function makeStarInfo($obj:Object):void
		{
			setBtnstatus($obj.status1,1);
			setBtnstatus($obj.status2,2);
			setBtnstatus($obj.status3,3);
			setBtnstatus($obj.status4,4);
			setBtnstatus($obj.status5,5);
			setBtnstatus($obj.status6,6);
			setBtnstatus($obj.status7,7);
		}
		/**
		 *领取奖励返回 
		 * 
		 */
		public 	function award($obj:Object):void
		{
			addEvtListener();
			if(!$obj.status)return;
			setBtnstatus(2,_selectId);
		}
		/**
		 *设置按钮状态  
		 * type,0.未领取，1.已完成，2已领取 value 
		 */
		private function setBtnstatus(type:int,value:int):void
		{
			switch(type)
			{
				case 0:
					symbolSkin["btn_" +value].mouseEnabled = false;
					symbolSkin["btn_" +value].visible = true;
					symbolSkin["btn_" +value].filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0.3086, 0.6094, 0.082, 0, 0,
						0,0,0,1,0,])];
					break;
				case 1:
					symbolSkin["btn_" +value].filters = null;
					symbolSkin["btn_" +value].visible = true;
					symbolSkin["btn_" +value].mouseEnabled = true;
					break;
				case 2:
					symbolSkin["btn_" +value].visible = false;
					symbolSkin["btn_" +value].mouseEnabled = false;
					break;
			}
		}
	}
}